package com.woniuxy.happylife.auth.service.Impl;

import com.woniuxy.happylife.entity.User;
import org.apache.shiro.crypto.hash.SimpleHash;
import org.springframework.stereotype.Service;
import com.woniuxy.happylife.auth.dao.LoginDao;
import com.woniuxy.happylife.auth.service.LoginService;

import javax.annotation.Resource;

/**
 * @Title: LoginServiceImpl
 * @ProjectName: happy-life
 * @Description: TODO
 * @Author: chowinggum
 * @Date: 2022/2/18 20:27
 */
@Service
public class LoginServiceImpl implements LoginService {

    @Resource
    LoginDao loginDao;

    @Override
    public User login(String username, String password) {
        //将密码转成加密后的形式
        SimpleHash simpleHash = new SimpleHash("MD5", password, "woniuxy" + username);
        //转成十六进制编码
        password = simpleHash.toHex();
        //用加密后的用户名密码去数据库查询user
        User user = loginDao.findByUsernameAndPassword(username, password);

        return user;
    }

    @Override
    public int enroll(String username, String password) {
        //将密码转成加密后的形式
        SimpleHash simpleHash = new SimpleHash("MD5", password, "woniuxy" + username);
        //转成十六进制编码
        password = simpleHash.toHex();
        //用加密后的用户名密码去数据库查询user
        return loginDao.enroll(username, password);
    }

}
